package org.yunshang.color.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import org.yunshang.color.domain.bo.TColorBo;
import org.yunshang.color.domain.vo.TColorVo;
import org.yunshang.color.service.ITColorService;
import org.yunshang.common.excel.utils.ExcelUtil;
import org.yunshang.common.idempotent.annotation.RepeatSubmit;
import org.yunshang.common.log.annotation.Log;
import org.yunshang.common.web.core.BaseController;
import org.yunshang.common.mybatis.core.page.PageQuery;
import org.yunshang.common.core.domain.R;
import org.yunshang.common.core.validate.AddGroup;
import org.yunshang.common.core.validate.EditGroup;
import org.yunshang.common.log.enums.BusinessType;

import org.yunshang.common.mybatis.core.page.TableDataInfo;

/**
 * 颜色管理
 *
 * @author Lion Li
 * @date 2024-03-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/color")
public class TColorController extends BaseController {

    private final ITColorService tColorService;

    /**
     * 查询颜色管理列表
     */
    @SaCheckPermission("business:color:list")
    @GetMapping("/list")
    public TableDataInfo<TColorVo> list(TColorBo bo, PageQuery pageQuery) {
        return tColorService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出颜色管理列表
     */
    @SaCheckPermission("business:color:export")
    @Log(title = "颜色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TColorBo bo, HttpServletResponse response) {
        List<TColorVo> list = tColorService.queryList(bo);
        ExcelUtil.exportExcel(list, "颜色管理", TColorVo.class, response);
    }

    /**
     * 获取颜色管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:color:query")
    @GetMapping("/{id}")
    public R<TColorVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tColorService.queryById(id));
    }

    /**
     * 新增颜色管理
     */
    @SaCheckPermission("business:color:add")
    @Log(title = "颜色管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TColorBo bo) {
        return toAjax(tColorService.insertByBo(bo));
    }

    /**
     * 修改颜色管理
     */
    @SaCheckPermission("business:color:edit")
    @Log(title = "颜色管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TColorBo bo) {
        return toAjax(tColorService.updateByBo(bo));
    }

    /**
     * 删除颜色管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:color:remove")
    @Log(title = "颜色管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tColorService.deleteWithValidByIds(List.of(ids), true));
    }
}
